class Solution {
    public String longestPalindrome(String s) {
        if(null == s||0 == s.length()) {
            return "";
        }
        int len = 0;
        int maxlen = 0;
        int start = 0;
        int end = 0;
        for(int i = 0;i<s.length();i++) {
            int left = i-1;
            int right = i+1;
            while(left>=0&&s.charAt(left) == s.charAt(i)) {
                left--;
                len++;
            }
            while(right<s.length()&& s.charAt(right) == s.charAt(i)) {
                right++;
                len++;
            }
            while(left>=0 && right<s.length()&& s.charAt(right) == s.charAt(left)) {
                left--;
                right++;
                len+=2;
            }
            if(maxlen<len) {
                maxlen = len;
                start = left+1;
                end = right-1;
            }
            len = 0;
        }
        return s.substring(start,end+1);
        
    }
}